package com.huaxia.day5a;

import com.huaxia.day3.Colour;

public class FlowControl {

    private static char B = 'B';
    private char C = 'C';

    private int[] ages = {};

    public static void main(String[] args) {
//        ifElse();

//        switchCase();
//          while1();
//          doWhile();
//        forBreak();
        forContinue();
//        FlowControl control = new FlowControl();
//        System.out.println(control.judgeColour(Colour.RED));
//        for2();
//        forEachs2();

        //    switch2();

//        forEachs();
    }

    /**
     * if else 分支控制
     */
    public static void ifElse() {
        int age = 10;
        if (age > 60) {
            System.out.println("是老人");
        } else if (age > 18) {
            System.out.println("成年人");
        } else if (age > 12) {
            System.out.println("青少年");
        } else {
            System.out.println("儿童");
        }
    }

    /**
     * switch case
     */

    public static void switchCase() {
        char grade = 'A';

        switch (grade) {
            case 'A': {
                System.out.println("85~100");
                break;
            }
            case 'B': {
                System.out.println("70~84");
                break;
            }
            case 'C': {
                System.out.println("60~69");
                break;
            }
            default: {
                System.out.println("没有分数");
            }
        }
    }

    public String judgeColour(Colour colour) {
        switch (colour) {
            case RED: {
                return "红色";
            }
            case BLUE: {
                return "蓝色";
            }
            case YELLOW: {
                return "黄色";
            }
            default:
                return "颜色未知";
        }
    }

    /**
     * while
     */
    public static void while1() {
        int k = 10;
        while (k < 10) {
            System.out.println("while:"+k++);
        }
    }

    public static void doWhile() {
        int k = 10;
        do {
            System.out.println("do while:"+k++);
        } while (k < 10);
    }

    /**
     * foreach
     */

    public static void forEachs() {
        int[] tt = {1, 2, 3, 4, 5};


        for (int i = tt.length-1; i > -1; i--) {
            System.out.println(tt[i]);
        }
            System.out.println("******************");
        for (int v : tt) {
            System.out.println(v);
        }
    }






    public static void forEachs2() {
        int[] tt = {1, 2, 3, 4, 5};
        for (int i = tt.length-1; i > -1; i--) {
            if (tt[i] == 3){
                continue;
            }
            System.out.println(tt[i]);
        }
        System.out.println("******************");
    }
















    public static void for2() {
        for (int i = 10; i > 0; i--) {
            for (int k = 1; k <= i; k++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    /**
     * for break continue
     */
    public static void forBreak() {
        int start = 0;
        int result = 0;
        for (int i = 0; i < 5; i++) {
            start++;
            if (start % 3 == 0) {
                break;
            }
            result += start;
            System.out.print(start);
            System.out.print(",");
        }
        System.out.println();
        System.out.println("break:" + result);
    }

    public static void forContinue() {
        int start = 0;
        int result = 0;
        for (int i = 0; i < 5; i++) {
            start++;
            if (start % 2 == 0) {
                continue;
            }
            System.out.print(start+",");
            result += start;
        }
        System.out.println();
        System.out.println("continue:" + result);
    }

    public static void switch2() {
        int a = 2;
        switch (a) {
            default:
                System.out.println("default");
            case 0:
                System.out.println("0");
            case 1:
                System.out.println(1);
                break;
            case 2:
                System.out.println(2);
            case 4:
                System.out.println(4);
        }
    }
}
